import { defineStore } from 'pinia'

const useSystemInitStore = defineStore('sysInit', {
    state: () => ({
        places: [],  /// 事发地点
        causes: [],  /// 意外伤害原因
        ways: [],  /// 处理方式
        groups: [],  /// 就诊原因
        positions: [],  /// 受伤部位
    }),
    actions: {
        setPlacesList(list) {
            this.places = list
        },
        setCauseList(list) {
            this.causes = list
        },
        setWaysList(list) {
            this.ways = list
        },
        setGroupsList(list) {

            let glist = list
            for(let i = 0; i < glist.children.length; i++) {
                let gitems = glist.children[i]
                
                const glistTitle = gitems.label
                let glistid = gitems.id
                for( let k = 0; k < gitems.children.length; k++) {
                    let gitem = gitems.children[k]
                    gitem.gname = "[" + glistTitle+"]"+gitem.label
                    gitem.gid = '02^'+glistid + '^' + gitem.id
                }
            }
            this.groups = glist
        },
        setPositionsList(list) {
            this.positions = list
        },
    },

    persist: {
        enabled: true,
        strategies: [
            {
              key: 'sysInit',
              storage: localStorage,
            },
        ],
    }
})

export default useSystemInitStore